package programme;

import  ilog.concert.*;
import  ilog.cplex.*;

/*
 * The problem to be solved:
 * Maximize	x1 + 2x2 + 3x3
 * s.t.		-x1 + x2 + x3 <= 20
 * 			x1 - 3x2 + x3 <= 30
 * bounds	0 <= x1 <= 40
 * 			x2 >= 0
 * 			x3 >= 0
 * 
 * */



public  class  Example  {
	public  static  void  main(String[]  args)  {
		try  {
			IloCplex  cplex  =  new  IloCplex();
			
			//Bornes inférieures
			double[]        lb  =  {0.0,  0.0,  0.0};
			
			//Bornes supérieures
			double[]        ub  =  {40.0,  Double.MAX_VALUE,  Double.MAX_VALUE};
			
			//Nombre de variables
			IloNumVar[]  x    =  cplex.numVarArray(3,  lb,  ub);
			
			//Coefficients devant les variables
			double[]  objvals  =  {1.0,  2.0,  3.0};
			
			//Fonction objectif
			cplex.addMaximize(cplex.scalProd(x,  objvals));
			
			//Première contrainte
			cplex.addLe(cplex.sum(cplex.prod(-1.0,  x[0]),
				cplex.prod(  1.0,  x[1]),
				cplex.prod(  1.0,  x[2])),  20.0);
			
			//Deuxième contrainte
			cplex.addLe(cplex.sum(cplex.prod(  1.0,  x[0]),
				cplex.prod(-3.0,  x[1]),
				cplex.prod(  1.0,  x[2])),  30.0);
			
			//Résolution du problème
			if(cplex.solve()) {
				cplex.output().println("Solution  status  =  "  +  cplex.getStatus());
				cplex.output().println("Solution  value    =  "  +  cplex.getObjValue());
				
				double[]  val  =  cplex.getValues(x);
				int  ncols  =  cplex.getNcols();
				
				for(int  j  =  0;  j  <  ncols;  ++j)
					cplex.output().println("Column:  "  +  j  +  "  Value  =  "  +  val[j]);
			}
			
			cplex.end();
		}
		catch (IloException  e) {
			System.err.println("Concert  exception  '"  +  e  +  "'  caught");
		}
	}
}